home *** CD-ROM | disk | FTP | other *** search
- Path: electra.saaf.se!not-for-mail
- From: pausch@electra.saaf.se (Paul Schlyter)
- Newsgroups: comp.arch.arithmetic,comp.lang.c,comp.lang.c++
- Subject: Re: Access carry flag from C
- Date: 25 Feb 1996 09:50:01 +0100
- Organization: Svensk Amat|rAstronomisk F|rening
- Message-ID: <4gp7rq$i63@electra.saaf.se>
- References: <Dn1C9z.DGv.0.net@indra.com>
- NNTP-Posting-Host: electra.saaf.se
-
- In article <Dn1C9z.DGv.0.net@indra.com>,
- Steve Sullivan <sullivan@indra.com> wrote:
-
- > Is it possible to determine if a fixed point overflow has
- > occurred from within C? For example:
- > i = j + k;
- > if (overflowed) ....;
-
- Only using inline assembly, or some other way of directly accessing
- the CPU registers, i.e. the method would be very implementation
- dependent.
-
- One example: Using Borlands C/C++ on PC's one could do like this:
-
- i = j + k;
- if ( _FLAGS & mask ) .....;
-
- where _FLAGS is a reserved word which directly maps into the CPU
- flag register, and mask is an appropriate mask value set by the
- programmer, depending on what kind of overflow he wants to detect.
- If he wants to detect signed overflow, he should check the OVERFLOW
- flag, if he wants to detect unsigned overflow he should check the
- CARRY flag.
-
- C has no portable way to check for integer (?) overflow. Unless you'd
- want to do stuff like:
-
- if ( ((double) j) + ((double) k) > MAX_INT ) ......
-
- --
- ----------------------------------------------------------------
- Paul Schlyter, Swedish Amateur Astronomer's Society (SAAF)
- Grev Turegatan 40, S-114 38 Stockholm, SWEDEN
- e-mail: pausch@saaf.se psr@home.ausys.se
-